package com.sc.nft.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyHatchIncomeConfRelevance;
import com.sc.nft.entity.vo.ecology.AdminEcologyIncomeConfPageVO;
import com.sc.nft.mapper.EcologyHatchIncomeConfRelevanceMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * 生态-收益-配置(sc_ecology_hatch_income_conf)数据DAO
 *
 * @author Sun
 * @since 2023-10-13 17:22:11
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class EcologyHatchIncomeConfRelevanceDao extends ServiceImpl<EcologyHatchIncomeConfRelevanceMapper, EcologyHatchIncomeConfRelevance> {

    public IPage<AdminEcologyIncomeConfPageVO> adminIncomeConfPage(Integer pageNo, Integer pageSize, Long hatchCollectionId, Boolean isOpen) {
        return baseMapper.adminIncomeConfPage(new Page<>(pageNo,pageSize), hatchCollectionId, isOpen);
    }

    public boolean updateTotalIncomeScaleAndHatchCollectionId(Long id,Long hatchCollectionId,String hatchCollectionName, BigDecimal sumTotal) {
        LambdaUpdateWrapper<EcologyHatchIncomeConfRelevance> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchIncomeConfRelevance::getId,id);
        wrapper.set(EcologyHatchIncomeConfRelevance::getTotalIncomeScale,sumTotal);
        wrapper.set(EcologyHatchIncomeConfRelevance::getHatchCollectionName,hatchCollectionName);
        wrapper.set(EcologyHatchIncomeConfRelevance::getHatchCollectionId,hatchCollectionId);
        return update(wrapper);
    }

    public int checkHatchCollectionBind(Long id, Long hatchCollectionId) {
        LambdaQueryWrapper<EcologyHatchIncomeConfRelevance> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.ne(Objects.nonNull(id),EcologyHatchIncomeConfRelevance::getId,id);
        lambdaQueryWrapper.eq(EcologyHatchIncomeConfRelevance::getHatchCollectionId,hatchCollectionId);
        return count(lambdaQueryWrapper);
    }

    public boolean updateIsOpen(Long id, Boolean isOpen) {
        LambdaUpdateWrapper<EcologyHatchIncomeConfRelevance> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(EcologyHatchIncomeConfRelevance::getId,id);
        updateWrapper.set(EcologyHatchIncomeConfRelevance::getIsOpen,isOpen);
        return update(updateWrapper);
    }

    public List<EcologyHatchIncomeConfRelevance> getOpen() {
        LambdaQueryWrapper<EcologyHatchIncomeConfRelevance> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EcologyHatchIncomeConfRelevance::getIsOpen,Boolean.TRUE);
        return list(lambdaQueryWrapper);
    }
}